package org.fujene.sandbox;

import java.io.UnsupportedEncodingException;

import org.fujene.toolbox.ByteConverter;

import junit.framework.TestCase;

public class TestByte extends TestCase{
	public static void testMain(){
		int i = -1;
		byte[] b = ByteConverter.intToByte(i, 3);
		int l = ByteConverter.byteToInt(b);
		System.out.println(i + " -> " + l);
	}

	public static void testStr() throws UnsupportedEncodingException{
		String str = "す";

		byte[] b = str.getBytes("UTF-8");

		String newstr = new String(b, "UTF-8");

		System.out.println(newstr);
	}

	private void recursion(int left){
		if (left > 0) rec1(left - 1);
	}

	private void rec1(int left){
		if (left > 0) rec2(left - 1);
	}

	private void rec2(int left){
		if (left > 0) rec3(left - 1);
	}

	private void rec3(int left){
		if (left > 0) rec4(left - 1);
	}

	private void rec4(int left){
		if (left > 0) rec5(left - 1);
	}

	private void rec5(int left){
		if (left > 0) recursion(left - 1);
	}

	public static void testOverhead(){
		TestByte rec = new TestByte();

		long time = System.nanoTime();
		rec.recursion(10);
		System.out.println("Recursion 10: " + ((System.nanoTime() - time) / 1000000.0) + " ms");
		time = System.nanoTime();
		rec.recursion(20);
		System.out.println("Recursion 20: " + ((System.nanoTime() - time) / 1000000.0) + " ms");
		time = System.nanoTime();
		rec.recursion(30);
		System.out.println("Recursion 30: " + ((System.nanoTime() - time) / 1000000.0) + " ms");
		time = System.nanoTime();
		rec.recursion(40);
		System.out.println("Recursion 40: " + ((System.nanoTime() - time) / 1000000.0) + " ms");
	}
}
